<template>
    <!--左侧房源筛选-->
    <div class="lefMain">
        <!--左侧1-->
        <span class="leftTop">
            <span style="font-size: 18px;white-space: nowrap;color:#7a8df1;font-weight: 600;">{{ $t('text.Contract.l49')
            }}</span>
        </span>

        <!--左侧3-->
        <div>
            <div class="leftTop2">

                <div class="df">
                    <img class="img2" src="../../assets/images/icon.png" />
                    <div class="time">
                        {{ $t('text.Contract.l50') }}
                        <el-date-picker v-model="time" type="daterange" unlink-panels range-separator="-"
                            start-placeholder="Start date" end-placeholder="End date" :size="'small'"
                            style="width: 100px;margin-left: 10px;" value-format="YYYY-MM-DD" />
                    </div>
                </div>

                <div class="df">
                    <img class="img2" src="../../assets/images/icon.png" />
                    <div class="items">
                        <RadioSelect :leftText="$t('text.Contract.l52')" :selectList="orgTreeList" searchKey="orgIds"
                            isShowTitle @returnData="setData" @clearData="clearData" isRange2 :isReset="isReset">
                        </RadioSelect>
                    </div>
                </div>

                <div class="df">
                    <img class="img2" src="../../assets/images/icon.png" />
                    <div class="items">
                        <RadioSelect :leftText="$t('text.Contract.l53')" :selectList="getSelectData('dealPlanStatus1')" :isReset="isReset"
                            searchKey="dealPlanStatus"  @returnData="setData" @clearData="clearData" isSingle>
                        </RadioSelect>
                    </div>
                </div>

                <div class="df">
                    <img class="img2" src="../../assets/images/icon.png" />
                    <div class="items">
                        <RadioSelect :leftText="$t('text.Contract.l54')" :selectList="getSelectData('payMethod')" :isReset="isReset"
                            searchKey="payMethod"  @returnData="setData" @clearData="clearData" isSingle>
                        </RadioSelect>
                    </div>
                </div>

            </div>
        </div>
        <div class="resetDiv" @click="reset">{{ $t('text.Contract.l32') }}</div>

    </div>

    <!--右侧房源列表-->
    <div class="rightMain">
        <!--右侧顶部导航-->
        <div class="rightTop">
            <div></div>
            <div></div>
            <div class="out" @click="this.$router.push({ path: '/transactionTemplate' })">
                <img class="outImg" src="../../assets/images/h61.svg">
                <span style="color: #6698ff;">{{ $t('text.Contract.l61') }}</span>
            </div>
        </div>
        <!--右侧房源数据列表-->
        <div class="rightContain">

            <table class="rightList" v-if="resultList.length > 0">
                <tr class="eDataList" v-for="item in resultList" v-bind:key="item" 
                @click="this.$router.push({ path: '/contractDetail', query: { id: item.contractId, index: item.contractType } })">
                    <td class="dataDom">
                        <div class="dataTitle">{{ item.no == null ? '-' : item.no }}</div>
                        <div class="dataValue" v-if="item.type != '' || item.type != null">
                            <span :class="'tag' + item.dealPlanStatus">
                                {{ item.dealPlanStatus == '1' ? $t('text.Contract.l62') : '' }}
                                {{ item.dealPlanStatus == '2' ? $t('text.Contract.l63') : '' }}
                            </span>
                        </div>
                    </td>
                    <td class="dataDom">
                        <div class="dataTitle">
                            {{ item.payMethod == null ? '-' : item.payMethod }}
                        </div>
                        <div class="dataValue">{{ item.templateName == null ? '-' : item.templateName }}</div>
                    </td>
                    <td class="dataDom">
                        <div class="dataTitle"
                            :style="item.dealPlanStatus == '2' ? { color: '#54d2d0', display: 'flex' } : { color: '#f7ad53', display: 'flex' }">
                            <div class="dotNumber">{{ item.stepSort == null ? '-' : item.stepSort }}</div>
                            {{ item.stepName == null ? '-' : item.stepName }}
                        </div>
                        <div class="dataValue" v-if="item.dealPlanStatus == '2'">
                            {{ $t('text.Contract.l58') }}&ensp;
                            <span :style="{ color: '#54d2d0' }">
                                {{ item.completeTime == null ? '-' : item.completeTime + ' ' }}
                            </span>
                        </div>
                        <div class="dataValue" v-if="item.dealPlanStatus == '1'">
                            {{ $t('text.Contract.l57') }}&ensp;
                            <span :style="{ color: '#f7ad53' }">
                                {{ item.planTime == null ? '-' : item.planTime + ' ' }}
                            </span>
                        </div>
                    </td>
                    <td class="dataDom">
                        <div class="dataTitle">
                            <span style="color:#5c5c5c">
                                {{ $t('text.Contract.l59') }}
                            </span>
                            {{ item.dealUserName == null ? '-' : item.dealUserName }}
                        </div>
                        <div class="dataValue">{{ item.signTime + ' ' + $t('text.Contract.l60') }}</div>
                    </td>
                </tr>
            </table>
            <div class="rightList" v-else>
                <div class="nulData">
                    {{ $t('text.Common.l67') }}
                </div>
            </div>
            <!--底部分页-->
            <div class="setPage">
                <el-pagination v-model:current-page="searchData.pageNo" v-model:page-size="searchData.pageSize"
                    :page-sizes="[10, 15, 20, 30, 50]" layout="total, sizes, prev, pager, next, jumper" :total="total"
                    @size-change="handleSizeChange" @current-change="handleCurrentChange" />
            </div>
        </div>
    </div>
</template>
    
<script>
import RadioSelect from "../../components/select/RadioSelect.vue"
import { findPageByPlan, getPlanDropdownBoxData, orgTreeNoUser } from '../../http/api'

export default {
    name: "TransactionProgress",
    components: {
        RadioSelect,
    },
    data() {
        return {
            searchData: {
                pageNo: 1,
                pageSize: 15,
            },
            resultList: [],
            isReset: false,
            total: 0,
            dictionaryTree: {},
            orgTreeList: [],
            time: "",
        }
    },
    mounted() {

        getPlanDropdownBoxData().then(res => {
            if (res !== undefined) {
                this.dictionaryTree = res
                console.log(res)
                orgTreeNoUser().then(res => {
                    if (res !== undefined) {
                        this.orgTreeList = res
                    }
                }).catch()
            }
        }).catch()

        this.search()

    },
    methods: {
        //获取字典数据
        getSelectData(key) {
            const data = this.dictionaryTree[key]
            if (data != undefined) {
                return this.dictionaryTree[key]
            } else {
                return [
                    {
                        dictName: "全部",
                        dictValue: "-1",
                    },
                ]
            }
        },

        //搜索数据
        search() {
            findPageByPlan(this.searchData).then(res => {
                if (res !== undefined) {
                    this.resultList = res.dataList
                    this.total=res.total
                    console.log(res)
                }
            }).catch()
        },

        //拼接单个子组件返回来的条件值
        setData(obj) {
            this.searchData = { ...this.searchData, ...obj }
            console.log(JSON.stringify(this.searchData))
        },

        //子组件选择了不限，进行删除指定字段
        clearData(obj) {
            const objKeys = Object.keys(obj)
            this.searchData = Object.keys(this.searchData).reduce((acc, key) => {
                if (!objKeys.includes(key)) {
                    acc[key] = this.searchData[key]
                }
                return acc
            }, {})
            console.log(JSON.stringify(this.searchData))
        },

        //重置
        reset() {
            this.searchData = {
                pageNo: 1,
                pageSize: 15,
            }
            this.isReset = !this.isReset
            this.time=''
        },
        handleSizeChange(val) {
            this.searchData.pageSize = val
            this.search()
        },
        handleCurrentChange(val) {
            this.searchData.pageNo = val
            this.search()
        },
    },
    watch: {
        searchData: {
            handler() {
                this.search()
            },
        },
        time() {
            if (this.time == null) {
                this.clearData({ signTimeBegin: "", signTimeEnd: "" })
            } else {
                let obj = { signTimeBegin: this.time[0], signTimeEnd: this.time[1] }
                this.searchData = { ...this.searchData, ...obj }
            }
        }
    },
    computed: {},
}
</script>
    
<style scoped>
.nulData {
    background-image: url('../../assets/images/nullData.svg');
    background-size: cover;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 25px;
    color: #979797;
}

.dotNumber {
    min-width: 14px;
    height: 16px;
    border-radius: 100%;
    border: 1px solid;
    font-size: 12px;
    text-align: center;
    padding: 0px 1px;
    transform: scale(0.8);
    font-weight: 500;
    margin-right: 5px;
}

.tag1 {
    border: 1px solid #f7ad53;
    padding: 0 10px;
    margin-right: 10px;
    border-radius: 4px;
    background: #f7ad5329;
    color: #f7ad53;
    font-size: 12px;
}

.tag2 {
    border: 1px solid #54d2d0;
    padding: 0 10px;
    margin-right: 10px;
    border-radius: 4px;
    background: #54d2d029;
    color: #54d2d0;
    font-size: 12px;
}

.resetDiv {
    background: #6698ff;
    margin-top: 20px;
    padding: 5px 0;
    font-size: 13px;
    color: white;
    border-radius: 7px;
}

.df {
    display: flex;
    align-items: center;
    margin-top: 8px;
    margin-bottom: 2px;
}

.lefMain {
    min-width: 310px;
    padding: 15px;
    overflow: auto;
    background: white;
    margin-bottom: 30px;
    margin-right: 5px;
    box-shadow: 1px 10px 30px 4px #e9e9e9;
}

.rightContain {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
    background: white;
    margin: 20px 30px 30px 25px;
    position: relative;
    box-shadow: 1px 5px 10px 4px #e9e9e9;
}

.leftTop {
    color: #6698ff;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.leftTop2 {
    border: 1px solid #cecece;
    border-radius: 5px;
    padding: 10px;
    margin-top: 10px;
    position: relative;
    padding-top: 0;
}

.img2 {
    width: 22px;
    height: 22px;
}

.items {
    margin-left: 15px;
    padding-top: 6px;
    padding-bottom: 6px;
    font-size: 12px;
    color: gray;
    border-bottom: 1px solid rgb(224, 224, 224);
    width: 100%;
}

.rightMain {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: #f8f8f8;
}

.rightList {
    height: 100%;
    display: flex;
    flex-direction: column;
    border-radius: 5px;
    overflow: auto;
    padding: 10px 0;
}

.rightTop {
    display: flex;
    padding-top: 15px;
    align-items: center;
    justify-content: space-between;
    padding-right: 32px;
}

.setPage {
    display: flex;
    justify-content: flex-end;
    border-top: 1px solid #eee;
    padding: 10px;
}

.out {
    display: flex;
    align-items: center;
    font-size: 14px;
}

.outImg {
    width: 20px;
    height: 20px;
    padding-right: 5px;
}

.img2 {
    width: 22px;
    height: 22px;
}

.time {
    margin-left: 15px;
    padding-top: 6px;
    padding-bottom: 6px;
    font-size: 12px;
    color: gray;
    border-bottom: 1px solid rgb(224, 224, 224);
    width: 100%;
    display: flex;
    align-items: center;
    white-space: nowrap;
    justify-content: space-between;
}

.eDataList {
    display: flex;
    align-items: flex-start;
    padding: 5px 30px;
    margin: 3px 0px;
    position: relative;
}

.eDataList::after {
    position: absolute;
    content: '';
    width: calc(100% - 60px);
    height: 1px;
    bottom: 0;
    border-bottom: 1px solid #eee;
    padding: 1px;
    margin-right: 30px;
}

.eDataList:hover {
    background: #eee;
}

.dataTitle {
    font-size: 13px;
    color: #6698ff;
    padding-bottom: 10px;
}

.dataValue {
    font-size: 13px;
    color: #5c5c5c;
    display: flex;
    flex-wrap: wrap;
}

.dataValue>span {
    margin-right: 5px;
    margin-bottom: 5px;
    white-space: nowrap;
}

.dataDom {
    flex: 1;
    text-align: left;
    padding-bottom: 5px;
}
</style>